<?php
//邮件发送函数
//require("mail/class.phpmailer.php"); 
load_file('class.phpmailer', LIB_PATH.'mail/');
function send_mail( $mail_to, $title_to, $content_to,$name_to,$mail_from,$mail_from_name,$mail_cc='',$send_type='0') {
	global $error_msg;
	$mail = new PHPMailer();
	if($send_type > 0){
		$mail->IsSendmail();							// send via Sendmail
	}else{
	
		$mail->IsSMTP(); 								// send via SMTP
	}
	               					             				
	$mail->SMTPAuth = true;         					// turn on SMTP authentication 
	$mail->IsHTML(true);  								// 是不支持html
	$mail->AltBody ="text/html";
	//$mail->Host = "smtp.qq.com"; 						// SMTP servers
	//$mail->Username = "514909613";   					// SMTP username  注意：普通邮件认证不需要加 @域名
	//$mail->Password = "xuwei8411023";        					// SMTP password
	$mail->Host = "smtp.exmail.qq.com"; 						// SMTP servers
	$mail->Username = "work@d2ziran.com";   					// SMTP username  注意：普通邮件认证不需要加 @域名
	$mail->Password = "1984215sw504";        					// SMTP password
	$mail->CharSet = "utf-8";            				// 这里指定字符集！
	$mail->Encoding = "base64";
	

	if(is_array($mail_to)){								// 多个地址时
	
		$num = count($mail_to);
		for($i=0;$i<$num;$i++){
			$mail->AddAddress($mail_to[$i],$name_to);
		}
	}else{
		$mail->AddAddress($mail_to,$name_to);  				// 收件人邮箱和姓名
	}
	
	if($mail_cc){
		if(is_array($mail_cc)){								// 多个抄送地址时
	
			$num = count($mail_cc);
			for($j=0;$j<$num;$j++){
				$mail->AddCC($mail_cc[$j],$name_cc);
			}
		}else{
			$mail->AddCC($mail_to,$name_to);  				// 抄送
		}
	}

	$mail->Subject = $title_to;							// 邮件主题				                                                                  
	$mail->Body = $content_to;							// 邮件内容 
	$mail->From = $mail_from;     						// 发件人邮箱
	$mail->FromName = $mail_from_name;  				// 发件人
	$mail->AddReplyTo($mail_from,$mail_from_name);		// 回复人邮箱和姓名
										
	//$mail->WordWrap = 50; // set word wrap
	//$mail->AddAttachment("/var/tmp/file.tar.gz"); 	// attachment
	//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
							
	if(!$mail->Send()){
		//echo "Sent mail error!\n";
		//echo "<br/>Error: " . $mail->ErrorInfo;
		echo $error_msg .="<br/>Error: ".$mail->ErrorInfo;
		return false;
	}
	else {
		//echo "sent successfully!\n";
		$mail->ClearAddresses();							// 删除地址和附件
    	$mail->ClearAttachments();
		return true;
	}
}





?>